<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="公历日期" prop="date">
        <el-input
          v-model="queryParams.date"
          placeholder="请输入公历日期"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="areaList">
      <el-table-column label="公历日期" align="center" prop="date" />
      <el-table-column label="工作日" align="center" prop="workday">
        <template slot-scope="scope">
          <div v-if="scope.row.workday == 1">是</div>
          <div v-if="scope.row.workday == 2">否</div>
        </template>
      </el-table-column>
      <el-table-column label="排单数量" align="center" prop="schedulingCount" />
      <el-table-column label="虚拟订单量" align="center" prop="virtuallyOrderCount" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >修改</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="95px">
        <el-form-item label="公历日期" prop="date1">
          <el-date-picker
            v-model="form.date1"
            type="date"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="工作日" prop="workday">
          <el-radio-group v-model="form.workday">
            <el-radio :label="1">是</el-radio>
            <el-radio :label="2">否</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="排单数量" prop="schedulingCount">
          <el-input v-model="form.schedulingCount" placeholder="请输入排单数量" />
        </el-form-item>
        <el-form-item label="虚拟订单量" prop="virtuallyOrderCount">
          <el-input v-model="form.virtuallyOrderCount" placeholder="请输入虚拟订单量" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
  
  <script>
import {
  dateInfoList,
  detailDate,
  modifyDate,
} from "@/api/dateInfo/dateInfo";
import { Debounce } from '@/utils/tools.js'
export default {
  name: "productCate",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      areaList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        date: "",
      },
      // 表单参数
      form: {
        date1: ''
      },
      // 表单校验
      rules: {
        date1: [
          { required: true, message: "请选择公厉日期", trigger: "change" },
        ],
        workday: [
          { required: true, message: "请选择工作日", trigger: "change" },
        ],
        schedulingCount: [
          { required: true, message: "请输入排单数量", trigger: "blur" },
        ],
        virtuallyOrderCount: [
          { required: true, message: "请输入虚拟订单量", trigger: "blur" },
        ]
      },
      dateVal: ''
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      dateInfoList(this.queryParams).then((response) => {
        this.areaList = response.data.records;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 修改按钮操作 */
    handleUpdate:Debounce(function (row) {
      this.reset();
      detailDate(row.date).then(response => {
        this.form = response.data;
        this.$set(this.form, 'date1', this.form.date.substring(0,4) + '-' + this.form.date.substring(4,6) + '-' + this.form.date.substring(6,8))
        this.open = true;
        this.title = "修改日期";
      });
    },500),
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 提交按钮 */
    submitForm:Debounce(function (row) {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.date) {
            let date = new Date(this.form.date1).getFullYear().toString().padStart(2, '0') + (new Date(this.form.date1).getMonth() + 1).toString().padStart(2, '0') + new Date(this.form.date1).getDate().toString().padStart(2, '0')
            this.form.date = date

            modifyDate(this.form).then((response) => {
              this.$modal.msgSuccess("编辑成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },500),
  },
};
</script>